
'''
876. 链表的中间结点
'''
from typing import Optional

from com.siyuan.ListNode import ListNode


class Solution:
    def middleNode(self, head: Optional[ListNode]) -> Optional[ListNode]:
        # 指针1
        fast = head
        # 指针2
        slow = head
        # 每当慢指针 slow 前进一步，快指针 fast 就前进两步，这样，当 fast 走到链表末尾时，slow 就指向了链表中点。
        while fast and fast.next:
            fast = fast.next.next
            slow = slow.next
        return slow
